package models;

import java.io.Serializable;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

@SuppressWarnings("serial")
public class OrderProductModel implements Serializable {

	private String productId = "";

	private String name = "";

	private int quantity = 0;
	
	private int inventory = 0;
	
	private int storeType = 0;
	
	private int productDelivered = 0;

	private int productReturn = 0;
	
	private int unitPrice = 0;
	
	private boolean checkOut = false;

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	
	public int getInventory() {
		return inventory;
	}

	public void setInventory(int inventory) {
		this.inventory = inventory;
	}
	
	public int getStoreType() {
		return storeType;
	}

	public void setStoreType(int storeType) {
		this.storeType = storeType;
	}
	
	public int getProductDelivered() {
		return productDelivered;
	}

	public void setProductDelivered(int productDelivered) {
		this.productDelivered = productDelivered;
	}

	public int getProductReturn() {
		return productReturn;
	}

	public void setProductReturn(int productReturn) {
		this.productReturn = productReturn;
	}

	public int getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(int unitPrice) {
		this.unitPrice = unitPrice;
	}

	public boolean isCheckOut() {
		return checkOut;
	}

	public void setCheckOut(boolean checkOut) {
		this.checkOut = checkOut;
	}

	public String toString() {
		StringBuilder content = new StringBuilder();
		if (this.productId != null) {
			content.append("<productId>" + this.productId + "</productId>\n");
		}
		if (this.name != null) {
			content.append("<name>" + this.name + "</name>\n");
		}
		if (this.quantity != 0) {
			content.append("<quantity>" + this.quantity + "</quantity>\n");
		}
		return content.toString();
	}

	public void getValueFromString(String orderProductString) {
		Document doc = Jsoup.parse(orderProductString);
		Elements tmp;
		tmp = doc.select("productId");
		if (tmp != null) {
			this.productId = (tmp.text());
		}
		tmp = doc.select("name");
		if (tmp != null) {
			this.name = (tmp.text());
		}
		tmp = doc.select("quantity");
		if (tmp != null) {
			try {
				int quantity = Integer.parseInt(tmp.text());
				this.quantity = (quantity);
			} catch (Exception e) {
				this.quantity = (0);
			}
		}
	}
}
